package cn.qvtu.web.controller;


import cn.qvtu.web.domain.AjaxResult;
import cn.qvtu.web.domain.Article;
import cn.qvtu.web.service.IArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author qvtu
 * @since 2024-04-22
 */
@Controller
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private IArticleService articleService;

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(Article article) {
        if (article.getId() == null) {
            article.setCreated(LocalDate.now());
        } else {
            article.setModified(LocalDate.now());
        }
        articleService.saveOrUpdate(article);
        return AjaxResult.success();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public AjaxResult delete(Long id){
        articleService.removeById(id);
        return AjaxResult.success();
    }

}

